package com.alumni_circle.core.mapper.rbac;

import com.alumni_circle.core.entity.rbac.RoleAuthority;
import com.alumni_circle.core.entity.rbac.VO.RoleAuthorityViewVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 龙小虬
 * @since 2020-08-02 20:37
 */
public interface RoleAuthorityMapper extends BaseMapper<RoleAuthority> {

    @Select("SELECT authority.permissions,role_name,role_authority.id,authority.url,role_authority.state,role.`comment` as role_comment,authority.`comment` as authority_comment,role_authority.update_time,role_authority.update_name\n" +
            "FROM role,role_authority,authority\n" +
            "WHERE role.id = role_authority.role_id AND role_authority.authority_id = authority.id")
    List<RoleAuthorityViewVO>getAllRoleAuthority();

    @Select("SELECT role_name,role_authority.id,authority.url,role_authority.state,role.`comment` as role_comment,authority.`comment` as authority_comment,role_authority.update_time,role_authority.update_name\n" +
            "FROM role,role_authority,authority\n" +
            "WHERE role.id = role_authority.role_id AND role_authority.authority_id = authority.id \n" +
            "AND (role_authority.id like concat('%',#{id},'%')) AND (authority.url like concat('%',#{url},'%')) AND (role.`comment` like concat('%',#{roleComment},'%')) AND (role_authority.state like concat('%',#{state},'%'))")
    List<RoleAuthorityViewVO> searchRoleAuthority(@Param("id")String id,@Param("url")String url,@Param("roleComment")String roleComment,@Param("state")String state);
}
